<!-- /*
 * @Author: RDSunday 
 * @Date: 2020-03-19 11:02:12 
 * @Last Modified by:   RDSunday 
 * @Last Modified time: 2020-03-19 11:02:12 
 */ -->
 <!-- javaScript按下回车键（enter)触发按钮点击事件 -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h3>按下Enter触发点击事件</h3>
    <p>选中输入框，然后按下"Enter" 就会触发按钮的点击事件。</p>
    <input id="myInput" value="一些文本">
    <button id="myBtn" onclick="javascript:alert('hello world!')">按钮</button>
    <script>
        var input = document.getElementById("myInput");
        input.addEventListener("keyup",function(event) {
            event.preventDefault();
            if (event.keyCode===13) {
                document.getElementById("myBtn").click();
            }

        })
    </script>
</body>
</html>